package string;

public class InverseStringExamle {

	public static void main(String[] args) {

		String initial = "123456";
		
		System.out.println(initial);

		String invertWithSB = invertWithSB(initial);
		System.out.println(invertWithSB + " - invertWithSB");

		String invertWithoutSB = invertWithoutSB(initial);
		System.out.println(invertWithoutSB + " - invertWithoutSB1");
		
		//String invertWithoutSB1 = invertWithoutSB1(initial);
		//System.out.println(invertWithSB + " - invertWithoutSB1");
	}

	private static String invertWithSB(String input) {
		StringBuilder sb = new StringBuilder(input);
		return sb.reverse().toString();
	}

	private static String invertWithoutSB(String input) {
		
		char[] array = input.toCharArray();
		
		for (int index = 0; index < array.length/2; index++) {
			
			System.out.println("index = " + index);
			char tempFromStart = array[index];
			System.out.println("tempFromStart = " + tempFromStart);
			
			char tempFromEnd = array[array.length - 1 - index];
			System.out.println("tempFromEnd = " + tempFromEnd);
			
			array[index] = tempFromEnd;
			array[array.length - 1 - index] = tempFromStart;
			
			System.out.println(array);
			System.out.println("======================");
		}
		
		return new String(array);
	}

//	private static String invertWithoutSB1(String input) {
//		char[] array = input.toCharArray();
//
//		//int length = charArray.length;
//		System.out.println("array.length / 2=" + (array.length / 2));
//		for (int i = 0; i < array.length / 2; i++) {
//			char tmp = array[i];
//			 System.out.println(tmp);
//			 System.out.println("i=" + i);
//			array[i] = array[array.length - i - 1];
//			array[array.length - i - 1] = tmp;
//			 System.out.println(array);
//		}
//		
//		return new String(array);
//	}
}
